//
//  WKCoinVM.m
//  LLWallet
//
//  Created by wangfei on 2025/9/15.
//

#import "WKCoinVM.h"

@interface WKCoinVM ()

@property(nonatomic,strong) NSArray<WKBiTypeInfoResp*> *items;

@end

@implementation WKCoinVM


- (NSArray<NSDictionary *> *)tableSectionMaps {
    __weak typeof(self) weakSelf = self;
    NSMutableArray<NSDictionary*> *itemDicts = [NSMutableArray array];
    if(self.items) {
        for (WKBiTypeInfoResp *item in self.items) {
            [itemDicts addObject:@{
                @"height":@(10.0f),
                @"items":@[
                        @{
                            @"class": WKCoinModel.class,
                            @"name": item.name?:@"",
                            @"des": item.coinName?:@"",
                            @"icon": item.logo?:@"",
                            @"onClick":^{
                                if(weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(ff_coinSelect:)]) {
                                    [weakSelf.delegate ff_coinSelect:item];
                                }
                            }
                        }
                ],
            }];
        }
    }
    return itemDicts;
}

- (void)requestData:(void (^)(NSError * _Nullable))complete {
    __weak typeof(self) weakSelf = self;
    [[WKAPIClient sharedClient] GET:@"udun/coin_types" parameters:nil].then(^(NSDictionary *resps){
        NSArray *listArr = resps[@"coinTypes"];
        NSMutableArray *arr = [NSMutableArray array];
        for (NSDictionary *dic in listArr) {
            WKBiTypeInfoResp *model = [WKBiTypeInfoResp new];
            model._id = dic[@"id"];
            model.name = dic[@"name"];
            model.type = [dic[@"mainCoinType"] integerValue];
            model.logo = dic[@"logo"];
            model.coinName = dic[@"coinName"];
            [arr addObject:model];
        }
        self.items = arr;
        complete(nil);
    }).catch(^(NSError *error){
        complete(error);
    });
}
@end

@implementation WKBiTypeInfoResp

+ (WKModel *)fromMap:(NSDictionary *)dictory type:(ModelMapType)type {
    WKBiTypeInfoResp *resp = [WKBiTypeInfoResp new];

    return resp;
}


@end



